package com.zzty.train.pjm.controller;


import com.zzty.train.pjm.entity.Question;
import com.zzty.train.pjm.entity.TeamExam;
import com.zzty.train.pjm.service.QuestionService;
import com.zzty.train.pjm.util.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/teamExam")
public class TeamExamController {

    @Autowired
    QuestionService questionService;
    @RequestMapping("/getQuestion")
    public List<Question> getContent(Integer pageNo){//获取当前页数
        Integer pageSize=5;//一页的数量
        List<Question>questions=questionService.getQuestion();
        Integer count=questionService.getQuestionCount();
        Integer t1=count/pageSize;
        Integer t2=count%pageSize;
        if(t1!=0){
            t2=t2+1;//获取总页数
        }
        Integer page=(pageNo-1)*5;
        PageUtils pageUtils=new PageUtils();
        pageUtils.setPageNo(page);
        pageUtils.setPageSize(pageSize);
        List<Question>getPageQuestioin=questionService.getPageQuestion(pageUtils);
        System.out.println("getPageQuestion"+getPageQuestioin.size());
        System.out.println("questions"+questions);
        return getPageQuestioin;
    }

    @RequestMapping("/getEndPage")
    public PageUtils getEndPage(){//获取当前页数
        Integer pageSize=5;//一页的数量
        List<Question>questions=questionService.getQuestion();
        Integer count=questionService.getQuestionCount();
        Integer t1=count/pageSize;
        Integer t2=count%pageSize;
        if(t2!=0){
            t1=t1+1;//获取总页数
        }
        Integer page=(t1-1)*5;
        PageUtils pageUtils=new PageUtils();
        pageUtils.setPageNo(page);
        pageUtils.setPageSize(pageSize);
        List<Question>getPageQuestioin=questionService.getPageQuestion(pageUtils);
        System.out.println("getPageQuestion"+getPageQuestioin.size());
        System.out.println("questions"+questions);
        PageUtils pageUtils1=new PageUtils();
        pageUtils1.setPageNo(t1);
        pageUtils1.setSumData(getPageQuestioin);
        return pageUtils1;
    }

    @RequestMapping("/getPreviousPage")
    public List<Question> getPreviousPage(Integer currentPage){//获取当前页数
        System.out.println("currentPage"+currentPage);
        Integer pageSize=5;//一页的数量
        Integer count=questionService.getQuestionCount();
        Integer t1=count/pageSize;
        Integer t2=count%pageSize;
        if(t2!=0){
            t1=t1+1;//获取总页数
        }
        System.out.println("currentPage"+currentPage);
        Integer page=(currentPage-1)*5;
        PageUtils pageUtils=new PageUtils();
        pageUtils.setPageNo(page);
        pageUtils.setPageSize(pageSize);
        List<Question>getPageQuestioin=questionService.getPageQuestion(pageUtils);
        System.out.println("getPageQuestion"+getPageQuestioin.size());
        return getPageQuestioin;
    }

    @RequestMapping("/getPageCount")
    public Integer getPageCount(){//获取当前页数
        Integer pageSize=5;//一页的数量
        Integer count=questionService.getQuestionCount();
        Integer t1=count/pageSize;
        Integer t2=count%pageSize;
        if(t2!=0){
            t1=t1+1;//获取总页数
        }
        return t1;
    }

    @RequestMapping("/getNextPage")
    public PageUtils getNextPage(Integer currentPage){//获取当前页数
        System.out.println("currentPage"+currentPage);
        Integer pageSize=5;//一页的数量
        Integer count=questionService.getQuestionCount();
        Integer t1=count/pageSize;
        Integer t2=count%pageSize;
        if(t2!=0){
            t1=t1+1;//获取总页数
        }
        System.out.println("currentPage"+currentPage);
        Integer page=(currentPage-1)*5;
        PageUtils pageUtils=new PageUtils();
        pageUtils.setPageNo(page);
        pageUtils.setPageSize(pageSize);
        List<Question>getPageQuestioin=questionService.getPageQuestion(pageUtils);
        System.out.println("getPageQuestion"+getPageQuestioin.size());
        PageUtils pageUtils1=new PageUtils();
        pageUtils1.setPageNo(t1);
        pageUtils1.setSumData(getPageQuestioin);
        return pageUtils1;
    }

    @RequestMapping("/addQuestion")
    public Integer addQuestion(Question question){
        Integer count=questionService.addQuestion(question);
        return count;
    }

    @RequestMapping("/referQuestion")
    public Integer referQuestion(TeamExam teamExam){
        System.out.println("teamExam"+teamExam.toString());
        Integer count=questionService.submitQuestion(teamExam);
        System.out.println(count);
        return count;
    }
}
